﻿using System.Web.Mvc;
using Model;
using Repository;
using UI.Helper;

namespace UI.Areas.Admin.Controllers
{
    public class InformationController : Controller
    {
        //
        // GET: /Admin/User/

        public ActionResult Index()
        {
            var repository = RepositoryManager.CreateInformationRepository();

            var model = repository.GetFirst();

            if (model != null)
                return View(model);

            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Index(Information model)
        {
            var repository = RepositoryManager.CreateInformationRepository();

            if (model != null)
            {
                var objInfo = repository.GetFirst();

                //update
                if (objInfo != null)
                {
                    objInfo.ViAboutUs = model.ViAboutUs;
                    objInfo.EnAboutUs = model.EnAboutUs;
                    objInfo.ViContact = model.ViContact;
                    objInfo.EnContact = model.EnContact;

                    repository.Update(model);
                    ViewData[Constants.MESSAGE] = "Đã cập nhật thành công";
                }
                //insert
                else
                {
                    repository.Insert(model);
                    ViewData[Constants.MESSAGE] = "Đã thêm nhật thành công";
                }
            }

            return View(model);
        }
    }
}